cmake_minimum_required(VERSION 3.8)
project(adr)

if(CACFG_COMB_BOARD_ORIN_LINUX)
	return()
endif()

#set(CMAKE_C_FLAGS "$ENV{CFLAGS} -O2 -g -Wall -pthread")
#set(CMAKE_CXX_FLAGS "$ENV{CFLAGS} -O2 -g -Wall -pthread -std=c++14")
set(CMAKE_C_FLAGS "$ENV{CFLAGS}  -Wall -pthread")
set(CMAKE_CXX_FLAGS "$ENV{CFLAGS}  -Wall -pthread -std=c++14")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output/bin)


set(INTERFACE_VERSION "53")
#获取所有cpp文件
file(GLOB_RECURSE 3RD_SRC 
        ${CMAKE_CURRENT_SOURCE_DIR}/third/cJSON/*.c* )

file(GLOB_RECURSE Source_Src ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c*)
set(ALL_COMPILE_SRC 
        ${3RD_SRC}
        ${Source_Src})

#获取所有h文件路径
file(GLOB_RECURSE INCLUDE  "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h*")
foreach(src ${INCLUDE})
    string(REGEX REPLACE "(.*)/.*h*$" "\\1" include_path ${src})
    list(APPEND my_include_dirs ${include_path})
endforeach()

list(APPEND my_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/third/json/) 
list(APPEND my_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/third/curl/) 
list(APPEND my_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/gtest/include/gtest/)
list(APPEND my_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/third/tencent_sdk/include)     
list(REMOVE_DUPLICATES my_include_dirs)

foreach(src ${my_include_dirs})
    message(STATUS inlcude_path:${src}) 
endforeach()



#add_compile_options(-g -fPIC -O2)

include_directories(${my_include_dirs})




set(TOP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
#include(${TOP_SOURCE_DIR}/release/Debug/${CONFIG_PLATFORM}/basic/share/cmake/BasicConfig.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third/s3_sdk/include)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/third/s3_sdk/lib)
include_directories(${TOP_SOURCE_DIR}/release/${CMAKE_BUILD_TYPE}/${CONFIG_PLATFORM}/interface/drive_interface/include)
#include_directories(${TOP_SOURCE_DIR}/release/${CMAKE_BUILD_TYPE}/${CONFIG_PLATFORM}/capilot/include)
link_directories(${TOP_SOURCE_DIR}/release/${CMAKE_BUILD_TYPE}/${CONFIG_PLATFORM}/interface/drive_interface/lib)
link_directories(${TOP_SOURCE_DIR}/release/${CMAKE_BUILD_TYPE}/${CONFIG_PLATFORM}/dds/usr/lib)
#link_directories(/home/xrui/gcc12_2/ca_build1.0/ca_yocto/meta-changan/source/dependence/Release/j6/glog/lib)
#include(${CMAKE_CURRENT_SOURCE_DIR}/../release/${CMAKE_BUILD_TYPE}/${CONFIG_PLATFORM}/capilot/share/cmake/CapilotConfig.cmake)
#include(${CMAKE_CURRENT_SOURCE_DIR}/../release/${CMAKE_BUILD_TYPE}/${CONFIG_PLATFORM}/capilot/lib/cmake/capilotConfig.cmake)
#include(${CMAKE_CURRENT_SOURCE_DIR}/../release/soc/${platform}/cmake/CaSocSdkConfig.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/../release/cmake/ReleaseConfig.cmake)

#add_compile_options(-DLOG_USE_KLOG -DLOG_USE_KLOG_EXT -DLOG_USE_CLOG)

link_directories(${TARGET_APP_DIR}/lib)
#用于屏蔽release和socsdk第三方编译warning，系统李金翠通知暂不屏蔽第三方
#add_compile_options(-Wno-cpp)

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/third/tencent_sdk/lib)
link_directories(${TARGET_APP_DIR}/lib/NeuSAR)
link_directories(${TARGET_APP_DIR}/usr/lib)

if(USE_AARCH64_ANDROID)
        message(STATUS Configure android-aarch64)
        link_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/dds/lib/aarch64_android)
        link_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/3rdlib/aarch64_android)
elseif(USE_TBOX)
        message(STATUS "Configure tbox-armv7")
        link_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/dds/lib/armv7_tbox)
        link_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/3rdlib/armv7_tbox)
else()
        message(STATUS Configure linux-x86)
        link_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/dds/lib/x86_linux)
        link_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/3rdlib/x86_linux)
        link_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/autodrive/swc_interface/interface/interface19/x86/lib)
        add_definitions(-DUSE_LOCAL_CONFIG=0)
endif()

list(REMOVE_ITEM ALL_COMPILE_SRC ${CMAKE_SOURCE_DIR}/src/main.cpp)
add_library(${PROJECT_NAME} SHARED ${ALL_COMPILE_SRC})
#strip命令删除so里面包含的debug信息
#add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
#            COMMAND ${CMAKE_STRIP} --strip-debug --strip-unneeded $<TARGET_FILE:${PROJECT_NAME}>
#)
#add_executable(${PROJECT_NAME} ${ALL_COMPILE_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)

if(USE_AARCH64_ANDROID)
        #target_link_libraries(${PROJECT_NAME}  -lddsc -ljsoncpp -lssl -lcrypto -lz -lcurl -lprotobuf -lmosquitto)
        target_link_libraries(${PROJECT_NAME}  -lddsc -ljsoncpp -lssl -lcrypto -lz -lcurl -lmosquitto)
elseif(USE_TBOX)
        target_link_libraries(${PROJECT_NAME}  -lddsc -ljsoncpp -lssl -lcrypto -lz -lcurl -lprotobuf)
else()
        #-ldrive_interface  -lprotobuf
        #target_link_libraries(${PROJECT_NAME}  ara_exec AdaptivePlatform -lddsc -ljsoncpp -lcurl -lssl -lcrypto -lprotobuf -lasf_logsdk -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lmosquitto basic_common basic_cm fmt klog)

        target_link_libraries(${PROJECT_NAME} ${capilot_LIBS} -lddsc -ljsoncpp -lcurl -lssl -lcrypto -lprotobuf fmt klog drive_interface z idn2 unistring glog unwind hbmem geos TencentDesensitizeSdk TencentSM aws-cpp-sdk-s3 aws-cpp-sdk-core dc_sdk)

        set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${INTERFACE_VERSION})
endif()

#install(TARGETS ${PROJECT_NAME} DESTINATION bin)
#install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION opt/${PROJECT_NAME}/bin)

#install(DIRECTORY 
#     ${CMAKE_CURRENT_SOURCE_DIR}/etc
#     DESTINATION etc
#)
#install(DIRECTORY 
#     ${CMAKE_CURRENT_SOURCE_DIR}/etc
#     DESTINATION opt/${PROJECT_NAME}
#)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/config DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/output)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/adr.yaml DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/output)
# 创建目标目录（如果不存在）
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/output/third_lib)

# 拷贝 lib 文件夹下所有内容到 output/third_lib
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third/s3_sdk/lib/
     DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/output/third_lib
     FILES_MATCHING PATTERN "*")
generate_version_file(${CMAKE_CURRENT_SOURCE_DIR}/output/${PROJECT_NAME}_version.json)

#include(${TOP_SOURCE_DIR}/release/cmake/ReleaseConfig.cmake)
add_and_install_debug_info(${PROJECT_NAME})
#google test

if(BUILD_GTEST)
        add_subdirectory(gtest)
endif()     

#add_subdirectory(test)

